package j2025.j03;

/**
 * @Author 猫大仙
 */
public class j0315 {
    public ListNode removeNthFromEnd(ListNode head, int n) {
        ListNode ret = new ListNode(-1);
        ret.next = head;
        ListNode prev = ret;
        ListNode cur = ret;
        while(n>0){
            cur = cur.next;
            n--;
        }
        while(cur.next!=null){
            cur = cur.next;
            prev = prev.next;
        }
        prev.next = prev.next.next;
        return ret.next;
    }
}
